package com.yl.chainStore.util

import com.alibaba.fastjson.JSONObject
import java.util.*

/**
 * @description :
 * @author :wf
 * @create :2021-08-25 17:30:00
 */

    /**
     *
     * Map转String
     * @param map
     * @return
     */
    fun getMapToString(map: Map<String, Any>): String? {
        val keySet = map.keys
        //将set集合转换为数组
        val keyArray = keySet.toTypedArray()
        //给数组排序(升序)
        Arrays.sort(keyArray)
        //因为String拼接效率会很低的，所以转用StringBuilder
        val sb = StringBuilder()
        for (i in keyArray.indices) {
            // 参数值为空，则不参与签名 这个方法trim()是去空格
            if (map[keyArray[i]].toString().trim { it <= ' ' }.isNotEmpty()) {
                sb.append(keyArray[i]).append(":").append(map[keyArray[i]].toString().trim { it <= ' ' })
            }
            if (i != keyArray.size - 1) {
                sb.append(",")
            }
        }
        return sb.toString()
    }

fun getUtilMap(map:Map<String,Any>):JSONObject{
    val c=JSONObject()
    if (map.isNotEmpty()) {
        val keySet: Set<String> = map.keys
        for (key in keySet) {
            for (value in keySet) {
                c[key]=value
            }
        }
    }
    return c
}
